package com.dai.chun.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dai.chun.dao.dao.JobDao;
import com.dai.chun.dao.impl.JobDaoImpl;
import com.dai.chun.dao.model.Job;
import com.dai.chun.util.PageSplitUtil;
/***
 * 
 * @author zdw
 *
 */
public class SelectServlet extends HttpServlet
{

	private static final long serialVersionUID = 1L;

	public SelectServlet()
	{
		super();
	}

	public void destroy()
	{
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
//		response.setCharacterEncoding("GBK");
		response.setContentType("text/xml");
		response.setHeader("Cache-Control", "no-cache");
		response.setCharacterEncoding("UTF-8");
		int dept_id = Integer.parseInt(request.getParameter("dept_id").toString());
		// 获得请求中参数为id的值
		String xml_start = "<selects>";
		String xml_end = "</selects>";
		String xml = "";
		
		JobDao jobDao=new JobDaoImpl();
		PageSplitUtil psu=new PageSplitUtil();
		List<Job> jobList=jobDao.listJobByDeptId(psu,dept_id);
		xml = "<select><value>0</value><text>请选择</text></select>";		
		if (0!=dept_id)
		{
			for(Job job:jobList){
				xml += "<select><value>"+job.getJob_id()+"</value><text>"+job.getJob_name()+"</text></select>";
			}
		}
		String last_xml = xml_start + xml + xml_end;
		response.getWriter().write(last_xml);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doGet(request, response);
	}

	public void init() throws ServletException
	{
	}

}
